let initdata = {
    arr:[]
}
let tablereducer = (state=initdata,{type,payload})=>{
    let newArr = JSON.parse(JSON.stringify(state.arr))
    switch(type ){
        case "getList1":
            newArr = payload
            return {
                ...state,
                arr:newArr
            }
        case "addfn":
            payload.key = new Date().getTime() // 数据里有key，生成一个时间戳key，一定不会key重复
            newArr.unshift(payload)
            return {
                ...state,
                arr:newArr
            }
        case "delFn":
            // payload.key = new Date().getTime() // 数据里有key，生成一个时间戳key，一定不会key重复
          
            let delIndex = newArr.findIndex((item) => { // 通过id找到我要删除哪一条的下标
                return item.id == payload
            })
            newArr.splice(delIndex,1)
            return {
                ...state,
                arr:newArr
            }
        case "editFn":
            payload.key = new Date().getTime() // 数据里有key，生成一个时间戳key，一定不会key重复
            newArr[payload.editIndex] = payload
            return {
                ...state,
                arr:newArr
            }
        case "searchfn":
            let newArr1 =  state.arr.filter((item,index)=>{
                return item.name1 == payload.name1 && item.state == payload.state
            })
        
            return {
                ...state,
                arr:newArr1
            }
        default:
            return {
                ...state
            }
    }
}
export default tablereducer